<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title>乐鲜生活-忘记密码</title>
	<link rel="shortcut icon" href="favicon.ico" />
	<link rel="bookmark" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="css/register.css" />
	<link rel="stylesheet" type="text/css" href="css/base.css" />
	<link rel="stylesheet" type="text/css" href="css/base1.css" />
	<link rel="stylesheet" type="text/css" href="css/asyncbox/asyncbox.css" />
	<style type="text/css">
		#validate:hover {
			color: #FF4200;
			cursor: pointer;
		}
		
		.password-z {
			font-size: 16px;
		}
	</style>
</head>
<body>
	<div id="wrapper">
		<div id="header"></div>
		<div class="main">
			<!--主体内容部分-->
			<div class="search search_marg">
				<!--搜索区域-->
				<div class="float_left reg_log">
					<!--商店图标-->
					<a href="index.html"><img src="icons/logo.png" alt="log"></a>
				</div>
				<div class="float_left reg_h3 z-margin1"
					style="margin: 30px 0 0 10px; color: #FF4200">
					<h3 class="za-spacial password-z">重置密码</h3>
				</div>
				<div class="clr"></div>
			</div>
			<div class="contentstart">
				<!--内容部分-->
				<div class="registerForm">
					<div>
						<span class="text"><span class="required"></span>手机号码：</span>
						<input type="text" class="span3" id="phone" placeholder="请输入手机号码" />
					</div>
					<div>
						<span class="text"><span class="required"></span>新的密码：</span>
						<input type="password" value="" placeholder="请输入新的密码" id="password" />
					</div>
					<div>
						<span class="text"><span class="required"></span>确认密码：</span>
						<input type="password" value="" placeholder="请再次输入新密码" id="surepassword" />
					</div>
					<div>
						<span class="text"><span class="required"></span>短信验证码：</span>
						<input type="text" value="" placeholder="请输入验证码" id="validateCode" />
						<input type="button" id="validate" class="validateCode" value="获取验证码" />
					</div>
					<div>
						<span class="text">&nbsp;</span>
						<a class="submit" id="submit" style="height: 25px; line-height: 25px">确认</a>
					</div>

				</div>
			</div>
		</div>
		<div id="footer"></div>
	</div>
	<script type="text/javascript" src="js/site/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="js/site/AsyncBox.v1.4.js"></script>
	<script type="text/javascript" src="js/site/validate.js"></script>
	<script type="text/javascript" src="js/site/common.js"></script>
	<script type="text/javascript">
		$(function() {
			var countdown = 60;
			function settime(obj) {
				if (countdown == 0) {
					$(obj).attr("disabled", false);
					$(obj).attr("value", "发送验证码");
					$(obj).css("cursor", "");
					countdown = 60;
				} else {
					$(obj).attr("disabled", true);
					$(obj).css("cursor", "default");
					$(obj).attr("value", countdown + "s");
					countdown--;
					setTimeout(function() {
						settime(obj);
					}, 1000);
				}
			}
	
			$("#validate").click(function() {
	
				var count = 60;
				var phone = $.trim($("#phone").val());
				if (!validateUtil.validateEmpty(phone)) {
					asyncbox.tips("手机号码不能为空，请输入手机号码!", asyncbox.Level.error);
					return;
				}
				if (!validateUtil.validatePhone(phone)) {
					asyncbox.tips("请输入正确的手机号码!", asyncbox.Level.error);
					return;
				}
				var param = {
					"phone" : phone,
					"type" : 2,
					"platform" : 2
				};
				$.postAjax("/validation/getValidateCode.do", param, function(json) {
					if (json.code) {
						asyncbox.tips(json.message, asyncbox.Level.error);
						return;
					}
					asyncbox.tips(json.message, asyncbox.Level.success);
					var obj = $("#validate");
					settime(obj);
				}, function() {
	
				});
			});
			$("#submit").click(function() {
				var phone = $.trim($("#phone").val());
				var password = $.trim($("#password").val());
				var surepassword = $.trim($("#surepassword").val());
				var validateCode = $.trim($("#validateCode").val());
				if (!validateUtil.validateEmpty(phone)) {
					asyncbox.tips("手机号码不能为空，请输入手机号码!", asyncbox.Level.error);
					return;
				}
				if (!validateUtil.validatePhone(phone)) {
					asyncbox.tips("请输入正确的手机号码!", asyncbox.Level.error);
					return;
				}
	
				if (!validateUtil.validateEmpty(password)) {
					asyncbox.tips("请输入新的密码!", asyncbox.Level.error);
					return;
				}
	
				if (!validateUtil.validateEmpty(surepassword)) {
					asyncbox.tips("请输入确认密码!", asyncbox.Level.error);
					return;
				}
	
				if (password != surepassword) {
					asyncbox.tips("两次密码不一致!", asyncbox.Level.error);
					return;
				}
	
				if (password.length <= 5 || surepassword <= 5) {
					return asyncbox.tips("密码长度必须6位以上！", asyncbox.Level.error)
				}
	
				if (!validateUtil.validateCode(validateCode, 6)) {
					return asyncbox.tips("请输入有效的验证码！", asyncbox.Level.error);
				}
				var data = {
					phone : phone,
					passWord : password,
					code : validateCode
				};
				$.postAjax("/user/resetPassword.do", data, function(json) {
					if (json.code) {
						asyncbox.tips(json.message, asyncbox.Level.error);
						return;
					}
					asyncbox.tips(json.message, asyncbox.Level.success);
					setTimeout(function() {
						window.location = 'login.html';
					}, 3000)
	
				}, function() {
					asyncbox.tips("网络连接错误", asyncbox.Level.error);
				});
			});
	
		});
	</script>
</body>
</html>
